package com.wwwzh.himalayafm.fragment;


import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wwwzh.himalayafm.adapter.PagerDownAdapter;
import com.wwwzh.himalayafm.R;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * 下载听碎片
 */
public class DownloadFragment extends Fragment {


    private ViewPager pager;
    String[] str = new String[]{"专辑", "声音", "下载中"};
    private List<String> data;

    public DownloadFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_download, container, false);
        initData();
        initView(rootView);
        // Inflate the layout for this fragment
        return rootView;
    }

    private void initData() {
        data = new ArrayList<>();
        for (int i = 0; i < str.length; i++) {
            data.add(str[i]);
        }
    }

    private void initView(View rootView) {
        pager = (ViewPager) rootView.findViewById(R.id.pager_down);
        PagerDownAdapter adapter = new PagerDownAdapter(getChildFragmentManager(), data);
        pager.setAdapter(adapter);
        TabLayout tab = (TabLayout) rootView.findViewById(R.id.down_tab);
        tab.setupWithViewPager(pager);
    }

}
